import { GuidePathInfo } from "../../../model/GuidePathInfo";
import { GameMapUtil } from "../../../scene/map/GameMapUtil";
import { MapNodeType } from "../../../scene/map/MapNodeType";
import { ObjectPool } from "../../../../../com/gengine/utils/pools/ObjectPool";
import { PathGuidePlayer } from "../../../scene/modle/PathGuidePlayer";
import { ModelType } from "../../../scene/modle/data/ModelType";
import { ActionType } from "../../../scene/modle/data/ActionType";
//class GuidePathView
    
    export  class GuidePathView /* flash.display.Sprite */
    {
        constructor()
        {
            
            this.initUI();
            return;
        }

        protected initUI(): void
        {
            mouseEnabled = false;
            mouseChildren = false;
            return;
        }

        public updateData(arg1: GuidePathInfo): void
        {
            this._point = arg1;
            this._point.point.value = GameMapUtil.getPointValue(this._point.x, this._point.y);
            this._isAlpha = MapNodeType.isAlpha(this._point.point.value);
            if (this._isAlpha) 
            {
                this.alpha = 0.6;
            }
            else 
            {
                this.alpha = 1;
            }
            this.x = this._point.pixx;
            this.y = this._point.pixy;
            if (!this.initArrow()) 
            {
                this.updateArrowDir();
            }
            return;
        }

        /* internal  */initArrow(): Boolean
        {
            if (this._arrow) 
            {
                return false;
            }
            else 
            {
                this._arrow = ObjectPool.getObject(PathGuidePlayer);
            }
            addChild(this._arrow);
            this._arrow.loadedPlay = false;
            this._arrow.loadComplete = this.onArrowLoadedHandler;
            this._arrow.load("guidePathArrow.swf", ModelType.GuidePath, null);
            if (this._arrow && this._arrow.movieClipData) 
            {
                this._arrow.movieClipData.isClear(false);
            }
            return true;
        }

        /* internal  */onArrowLoadedHandler(arg1: PathGuidePlayer): void
        {
            if (this._point) 
            {
                this.updateArrowDir();
            }
            else 
            {
                this.dispose();
            }
            return;
        }

        /* internal  */updateArrowDir(): void
        {
            if (this._arrow && this._point) 
            {
                this._arrow.updateFrame(ActionType.Stand, this._point.dir);
                this._arrow.gotoAndStop(0);
            }
            return;
        }

        public dispose(): void
        {
            if (this._arrow) 
            {
                if (this._arrow.movieClipData) 
                {
                    this._arrow.movieClipData.isClear(true);
                }
                this._arrow.dispose();
                ObjectPool.disposeObject(this._arrow, PathGuidePlayer);
                this._arrow = null;
            }
            if (this._point) 
            {
                this._point.dispose();
                ObjectPool.disposeObject(this._point, GuidePathInfo);
                this._point = null;
            }
            this._isAlpha = false;
            this.alpha = 1;
            return;
        }

        public get point(): GuidePathInfo
        {
            return this._point;
        }

        public get id(): string
        {
            if (this._point) 
            {
                return this._point.id;
            }
            return "";
        }

        /* internal */ /* var */_point: GuidePathInfo;

        /* internal */ /* var */_arrow: PathGuidePlayer;

        /* internal */ /* var */_isAlpha: Boolean;
    }
